Skip to main content

CNC Example 01: Generating OutQueue Directly

See the CNC01_direct.project sample project in the installation directory of CODESYS under ..\CODESYS SoftMotion\Examples.

This example shows a CNC program with two axes. Four positions are approached in the X/Y-plane with a defined velocity and acceleration. The program sets two path switch points on the path. The program is written directly into a data structure by using the SMC_OutQueue compile mode.

Creating an NC program in the CNC editor

  1. Create a CNCdirect project with a SoftMotion controller.

  2. Insert a CNC program object named Example.

    Select the ImplementationDin66025 and the Compile modeSMC_OutQueue.

  3. Specify the following motion blocks:

    CNC editor:

    _sm_img_example_cnc1_1.png

Creating a drive interface and PLC configuration

Define a drive structure with two linear drives as follows:

  1. Insert two virtual drives X_Drive and Y_Drive below the SoftMotion general axis pool.

  2. Set the Axis type parameter to Finite (1).

    Configuration editor:

    _sm_img_example_cnc1_7.png

Creating an IEC program

  1. Add a new CFC program Ipo to the application and configure a cyclic task with an interval of 3 ms.

  2. Activate the drive with the MC_Power function block.

    POUs:

    _sm_img_example_cnc1_2.png
  3. Insert the SMC_Interpolator POU. The function block converts a path defined by GEOINFO objects into discrete path points. The function block receives the address of the created CNC program at the input poqDataIn. Then the IEC task cycle time has to be written to the input dwIpoTime. You can specify these as constant values at the input dwIpoTime or you can use the variable dwCycle of the axis group structure from the PLC configuration. The advantage of this is that the correct time is automatically used as the interpolator input when you change the task cycle time.

    POU:

    _sm_img_example_cnc1_3.png
  4. In this example, a gantry system will be controlled. For this purpose, insert an instance of the inverse and forward transformation function blocks from the SM_Trafo library. The forward transformation function block contains the drives as inputs. The inverse transformation function block has to contain the set position of the interpolator. The forward transformation in the example is required for the visualization only.

    Function block instance:

    _sm_img_example_cnc1_4.png
    _sm_img_example_cnc1_5.png
  5. The outputs of the function block (the axis coordinates) have to be written to the drives. This is done with the SMC_ControlAxisByPos function block. Because the application does not guarantee that the outputs of the interpolator are constant (e.g. the path ends at a point other than where it began), activate the gap avoidance (bAvoidGaps, fGapVelocity, fGapAcceleration, and fGapDeceleration). Then connect the StopIpo output to the bEmergency_Stop input of the interpolator and connect interpolator output iStatus to the respective inputs of the axis control function blocks.

    Above all, pay attention to the correct order of function blocks when programming with CFC.

    CFC:

    _sm_img_example_cnc1_6.png

Creating an operating interface and a testing interface

Link two visualization objects to a new visualization: the template of the interpolator and the template of the transformation. You need to use placeholders to link these to the respective function block instances (here: Ipo.smci and Ipo.trafof).

Commissioning

Compile and start the created program. The program executes the CNC motion as soon as the Execute input of the interpolator has been set. After the program has run completely, you can apply a new rising edge to restart it.

Note the function of the path switches that are also displayed in the visualization of the interpolation function block.